class Solution:

    def addMinimum(self, word: str) -> int:
        ans = p = i = 0
        h = ['a', 'b', 'c']
        while i < len(word):
            if word[i] != h[p]:
                ans += 1
            else:
                i += 1
            p = (p + 1) % 3
        return ans + (3 - p) % 3